#include <iostream>
#include <chrono>
#include <gtest/gtest.h>
#include <libgo/coroutine.h>
#include "gtest_exit.h"
using namespace co;

#define O(x) std::cout << x << std::endl

template <int bytes>
void hold_stack() {
    char buf[bytes] = {};
    memset(buf, 0, sizeof(buf));
}

TEST(testProtect, testProtect) {
    co_opt.debug = co::dbg_task;
    co_opt.protect_stack_page = 1;
    co_opt.stack_size = 8192;
    co_opt.protect_stack_page = 0;
    co_opt.stack_size = 4096 * 10;

    go [] {
        hold_stack<4096>();
        hold_stack < 4096 + 2048 > ();
        hold_stack<4096 * 2>();
    };

    O("create task ok, will run it.");
    WaitUntilNoTask();
    O("run it done.");
}
